<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/config.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>题目对应年级</label>
                <div class="layui-input-inline">
                    <select id="grade-select">
                        <option value="一年级">一年级</option>
                        <option value="二年级">二年级</option>
                        <option value="三年级">三年级</option>
                        <option value="四年级">四年级</option>
                        <option value="五年级">五年级</option>
                        <option value="六年级">六年级</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="problem-content" class="layui-form-label">
                    <span class="x-red">*</span>题目内容</label>
                <div class="layui-input-inline">
                    <input type="text" id="problem-content" name="input1" required=""
                           autocomplete="off" class="layui-input" value=""></div>
            </div>

            <div class="layui-form-item">
                <label for="problem-content" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="mod-question" lay-submit="">确认修改</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer', 'jquery'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            $('#problem-content').val(localStorage.getItem("proContent"));

            //监听提交--修改题目
            form.on('submit(mod-question)',
                function (data) {
                    var quesContent = data.field.input1;
                    var gradeStr = $("#grade-select").val();
                    var proId = localStorage.getItem('proId');
                    data['problem'] = quesContent;
                    data['grade'] = gradeStr;
                    data['proId'] = proId;
                    console.log(JSON.stringify(data));
                    //发异步，把数据提交给后台
                    $.ajax({
                        headers: {
                            'Accept': 'application/json',
                            'Content-Type': 'application/json'
                        },
                        url: hostStr + "problem",
                        data:JSON.stringify(data),
                        type: "post",
                        dataType: "json",
                        success: function (res) {
                            console.log(res.params.proId);
                        }
                    });
                    layer.alert("成功修改题目", {
                            icon: 6
                        },
                        function () {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                            localStorage.setItem('toLoadPage', localStorage.getItem('currentPage'));
                        });
                    return false;
                });
        });
</script>
</body>
</html>
